package com.example.test_01.service;

import com.example.test_01.model.Food;
import com.example.test_01.utils.Result;

import org.litepal.LitePal;

import java.util.List;

public class FoodServiceImpl implements FoodService {
    @Override
    public Result Add(Food food) {
        if(food.save())
            return Result.SUCCESS;
        else
            return Result.ERROR;
    }

    @Override
    public Result DelFoodById(int id) {
        LitePal.delete(Food.class,id);
        return Result.SUCCESS;
    }

    @Override
    public List<Food> list() {
        return LitePal.findAll(Food.class);
    }

    @Override
    public List<Food> listByType(String name) {
        return LitePal.where("foodType = ?",name).find(Food.class);
    }
}
